<template>
  <div class="HomeIcons">
    <div class="row">
      <div class="col">
        <swiper :options="swiperOption" ref="mySwiper" v-if="disIcon">
          <swiper-slide v-for="item of iconGroup" :key="item.index">
            <div class="row">
              <div class="col-3 justify-content-center my-2" v-for="icon of item" :key="icon.id">
                <router-link :to="{name:'rouLink',params:{title:icon.title}}">
                  <div class="card border-0">
                    <img class="card-img-top" :src="icon.src" alt="Card image cap">
                    <div class="card-body p-0 text-center mt-0">
                      <p class="card-text text-dark">{{icon.title}}</p>
                    </div>
                  </div>
                </router-link>
              </div>
            </div>
          </swiper-slide>
          <!-- <div class="swiper-pagination" slot="pagination"></div> -->
          <div class="swiper-scrollbar" slot="scrollbar"></div>
        </swiper>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HomeIcons",
  props: {
    iconList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      swiperOption: {
        // pagination: ".swiper-pagination",
        loop: true,
        scrollbar: ".swiper-scrollbar"
      }
    };
  },
  computed: {
    disIcon() {
      return this.iconList.length;
    },
    iconGroup() {
      let icons = [],
        len = 8,
        seg = 0;
      this.iconList.forEach((item, index) => {
        seg = Math.floor(index / len);
        // console.log(index + "-" + seg + "-" + icons[seg]);
        if (!icons[seg]) {
          icons[seg] = [];
        }
        icons[seg].push(item);
      });
      return icons;
    }
  }
};
</script>


<style scoped>
</style>
